package com.smartrobot.controller;

import org.apache.log4j.Logger;
import org.jivesoftware.smack.Chat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.smartrobot.beans.Analysis;
import com.smartrobot.beans.ProcessResult;
import com.smartrobot.constant.Constants;
import com.smartrobot.conversation.IAnalyser;
import com.smartrobot.service.DeployService;

@Controller
public class DeployController extends BaseController{

	@Autowired
	private DeployService deployService;
	@Override
	public IAnalyser getAnalyser() {
		return new DeployAnalyser();
	}
	private static Logger log = Logger.getLogger(DeployController.class);

	@Override
	public ProcessResult processMessage(String message) {
		String []arg=message.split(" ");
		Chat chat=(Chat)this.getRequestAttribute(Constants.GTALK_CHAT);
		String result=deployService.deploy(arg,chat);
		ProcessResult pr=new ProcessResult();
		pr.setViewName("deployView");
		pr.addValue("deployResult", result);
		return pr;
	}

	public class DeployAnalyser implements IAnalyser{

		@Override
		public Analysis analyse(String input) {
			log.info("input is :"+input);
			Analysis ana=new Analysis();
			if(input.toLowerCase().startsWith("deploy")){
				ana.setHandleable(true);
			}
			return ana;
		}

		@Override
		public String getBeanName() {
			return "deployController";
		}
		
	}
}
